
#include "stm32f0xx.h"
#include "gpio.h"

#include "factorytest.h"

#define  PAin(x) ( (GPIOA->IDR & (1<<(x) )) >> (x) )
#define  PBin(x) ( (GPIOB->IDR & (1<<(x) )) >> (x) )

#define RX_SET_IN                   PAin(15)
#define TX_SET_IN                   PBin(3)

#define TXRX_SET_IN	  		    ( RX_SET_IN && TX_SET_IN  )

uint8_t GetStartMode(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    /* GPIOC Periph clock enable */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB, ENABLE);
    
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    
    if( (TX_SET_IN == 0)&&(RX_SET_IN == 0) )//TX&RX == 0
    {
        return FACTORY_TEST_LPMODE ;
    } 
    else if( (TX_SET_IN == 1)&&(RX_SET_IN == 0) )//TX&RX == 0)
    {
        return FACTORY_FINAL_TEST_MODE ;
    }
    else if( (TX_SET_IN == 0)&&(RX_SET_IN == 1) )//TX&RX == 0)
    {
        return FACTORY_MOTHERBOARD_TEST_MODE ;
    }
    else
    {
        return NORNAL_WORK_MODE ;
    } 
}